package cn.com.shopec.erp.core.base.entity;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.Transient;

import org.hibernate.annotations.GenericGenerator;

import cn.com.shopec.erp.core.constant.Constants;


/**
 * 实体类 - 基类
 */
@MappedSuperclass
public class BaseEntity implements Serializable {
	/**
	 * @Fields serialVersionUID : TODO
	 */
	private static final long serialVersionUID = -6718838800112233445L;
	/**
	 * "保存"方法名称
	 */
	public static final String ON_SAVE_METHOD_NAME = "onSave";

	/**
	 * "更新"方法名称
	 */
	public static final String ON_UPDATE_METHOD_NAME = "onUpdate";

	/**
	 * 主键ID
	 */
	private String id;

	/**
	 * 创建日期（时间戳）
	 */
	private Long createDate = System.currentTimeMillis();

	/**
	 * 修改日期（时间戳）
	 */
	private Long modifyDate;

	/**
	 * 删除标识，0：已删除；1：未删除；默认：1
	 */
	private Integer deleteFlag = Constants.DELETE_FLAG_NO;

	@Id
	@GenericGenerator(name = "generator", strategy = "uuid.hex")
	@GeneratedValue(generator = "generator")
	@Column(name = "id", unique = true, nullable = false)
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@Column(name = "create_date", updatable = false)
	public Long getCreateDate() {
		return createDate;
	}

	public void setCreateDate(Long createDate) {
		this.createDate = createDate;
	}

	@Column(name = "modify_date")
	public Long getModifyDate() {
		return modifyDate;
	}

	public void setModifyDate(Long modifyDate) {
		this.modifyDate = modifyDate;
	}

	@Column(name = "delete_flag")
	public Integer getDeleteFlag() {
		return deleteFlag;
	}

	public void setDeleteFlag(Integer deleteFlag) {
		this.deleteFlag = deleteFlag;
	}

	/**
	 * 保存前执行方法
	 * 
	 * @Title: onSave
	 * @Description: TODO
	 * @author: MyLife
	 * @date: 2013-1-29下午2:39:47
	 */
	@Transient
	public void onSave() {
	}

	/**
	 * 更新前执行方法
	 * 
	 * @Title: onUpdate
	 * @Description: TODO
	 * @author: MyLife
	 * @date: 2013-1-29下午2:39:59
	 */
	@Transient
	public void onUpdate() {
	}

	@Override
	public int hashCode() {
		return id == null ? System.identityHashCode(this) : id.hashCode();
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass().getPackage() != obj.getClass().getPackage()) {
			return false;
		}
		final BaseEntity other = (BaseEntity) obj;
		if (id == null) {
			if (other.getId() != null) {
				return false;
			}
		} else if (!id.equals(other.getId())) {
			return false;
		}
		return true;
	}

}